#include <QApplication>
#include <QFontDatabase>
#include <QFile>
#include <QSplashScreen>

#include "mainwindow.h"

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    a.addLibraryPath(QCoreApplication::applicationDirPath());
    QPixmap pixmap(":/resources/pics/splash.png");
    QSplashScreen splash(pixmap);
    splash.show();
    a.processEvents();
    //A workaround to fix qsplashscreen broken in qt 4.8
    splash.showMessage("Loading...");
    //Add local fonts shipped with the App.
    QFontDatabase::addApplicationFont(":/resources/fonts/Sanskrit2003.ttf");
    QFontDatabase::addApplicationFont(":/resources/fonts/DejaVuSans.ttf");
    QFile stylefile(":/resources/style/abhidhaana.css");

    //load the default stylesheet.
    if (!stylefile.open(QIODevice::ReadOnly | QIODevice::Text))
        return -1;
    QString styleSheet = "";

    while(!stylefile.atEnd()) {
        styleSheet += stylefile.readLine();
    }
    stylefile.close();

    qApp->setStyleSheet(styleSheet);
    //use our internal font.
    qApp->setFont(QFont("DejaVu Sans", 10));

    MainWindow w;
    w.show();
    splash.finish(&w);
    return a.exec();
}
